//From the bildr article: http://bildr.org/2012/03/servos-tlc5940-arduino
//Requires the Tlc5940 library. http://code.google.com/p/tlc5940arduino/downloads/list

#include "Tlc5940.h"
#include <tlc_config.h>
const int TLC_MAXIMUM = 4095;

int value = 0;
boolean valueDirection = false;

void setup(){
  Tlc.init(4095);
  Serial.begin(9600);
}

void loop() {
  if (value >= TLC_MAXIMUM || value <= 0) {
    valueDirection = !valueDirection;
  }
  if (valueDirection) {
    value += 10;
  } else {
    value -= 10;
  }
  value = constrain(value, 0, 4095);
  for (int i = 0; i < 16; i++) {
     setColor(i, value);
  }
  update();
  delay(10);
}

void setColor(int pin, int value) {
  Tlc.set(pin, TLC_MAXIMUM - value);
  //analogWrite(3, value);  
}

void update() {
  Tlc.update();
  delayMicroseconds(20);
}

